/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

/**
 *
 * @author MinhVu
 */
import webproxy.ACL_BlackList;
import webproxy.ACL_Filter;
import webproxy.MyPort;
import java.awt.HeadlessException;
import java.awt.event.ItemEvent;
import java.io.*;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import webproxy.Config;
import webproxy.Port_Thread;
import java.awt.Desktop;
import java.io.File;
import java.lang.Object;

public class MainFrame extends javax.swing.JFrame {
    Config config;
    Config config_history;
    ArrayList<Port_Thread > Listproxy ;
    ArrayList<MyPort> ListPort;
    ArrayList<ACL_BlackList> ListDomain;
    ArrayList<ACL_BlackList> ListIP;
    ACL_Filter filter;
    DefaultTableModel tblmodel;
    DefaultListModel lsDomainmodel;
    DefaultListModel lsIPmodel;
    FileInputStream fis;
    FileOutputStream fos;
    BufferedReader bffR;
    PrintStream ps;
    int flag = 0;
    int iCountPort=0;
    int indexListRow_Port = -1;
    int indexListRow_Domain =-1;
    int indexListRow_IP =-1;
    int iCountDomain =0;
    int iCountIP = 0;
    /**
     * Creates new form MainFrame
     */
    public MainFrame() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        palTop = new javax.swing.JPanel();
        btnHelp = new javax.swing.JButton();
        btnAbout = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        tabMain = new javax.swing.JTabbedPane();
        panelMain = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        btnAddPort = new javax.swing.JButton();
        btnEditPort = new javax.swing.JButton();
        btnRemovePort = new javax.swing.JButton();
        txtPortNumber = new javax.swing.JTextField();
        lbPort = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblPort = new javax.swing.JTable();
        btnStart = new javax.swing.JButton();
        lbTest = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        btnClearCache = new javax.swing.JButton();
        lbMb = new javax.swing.JLabel();
        lbMaxSize = new javax.swing.JLabel();
        cbCache = new javax.swing.JCheckBox();
        cbChangeProxy = new javax.swing.JCheckBox();
        lbHost = new javax.swing.JLabel();
        txtHost_ChangProxy = new javax.swing.JTextField();
        lbPort_ChangeProxy = new javax.swing.JLabel();
        txtPort_ChangeProxy = new javax.swing.JTextField();
        txtMaxSize = new javax.swing.JTextField();
        btnAplly_Config = new javax.swing.JButton();
        btnCancel_Config = new javax.swing.JButton();
        panelALC = new javax.swing.JPanel();
        lblName = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        cbImage = new javax.swing.JCheckBox();
        cbAudio = new javax.swing.JCheckBox();
        cbVideo = new javax.swing.JCheckBox();
        cbFlash = new javax.swing.JCheckBox();
        cbImage_All = new javax.swing.JCheckBox();
        cbAudio_All = new javax.swing.JCheckBox();
        cbVideo_All = new javax.swing.JCheckBox();
        cbFlash_All = new javax.swing.JCheckBox();
        cbLock = new javax.swing.JCheckBox();
        cbLock_All = new javax.swing.JCheckBox();
        jPanel7 = new javax.swing.JPanel();
        tabBlackList = new javax.swing.JTabbedPane();
        jPanel5 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        lstDomain = new javax.swing.JList();
        jPanel6 = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        lstIP = new javax.swing.JList();
        btnBlackList_Add = new javax.swing.JButton();
        btnBlackList_Update = new javax.swing.JButton();
        jLabel10 = new javax.swing.JLabel();
        txtBlackList_Info = new javax.swing.JTextField();
        btnBlackList_Delete = new javax.swing.JButton();
        btnACL_Cancel = new javax.swing.JButton();
        btnACL_Apply = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("NTV-Proxy");
        setBackground(new java.awt.Color(255, 255, 255));
        setBounds(new java.awt.Rectangle(400, 100, 0, 0));
        setName("MainFrame");
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        palTop.setBackground(new java.awt.Color(80, 80, 80));
        palTop.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        btnHelp.setText("Help");
        btnHelp.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnHelpMouseClicked(evt);
            }
        });

        btnAbout.setText("About");
        btnAbout.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnAboutMouseClicked(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tempus Sans ITC", 1, 20)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("NTV-Proxy");

        javax.swing.GroupLayout palTopLayout = new javax.swing.GroupLayout(palTop);
        palTop.setLayout(palTopLayout);
        palTopLayout.setHorizontalGroup(
            palTopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(palTopLayout.createSequentialGroup()
                .addGap(29, 29, 29)
                .addComponent(jLabel1)
                .addGap(439, 439, 439)
                .addComponent(btnHelp, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(36, 36, 36)
                .addComponent(btnAbout)
                .addContainerGap())
        );
        palTopLayout.setVerticalGroup(
            palTopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(palTopLayout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(palTopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnHelp, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnAbout, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel1))
                .addGap(23, 23, 23))
        );

        tabMain.setTabPlacement(javax.swing.JTabbedPane.LEFT);
        tabMain.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                tabMainStateChanged(evt);
            }
        });

        panelMain.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2));
        panelMain.setAutoscrolls(true);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Proxy - Port"));

        btnAddPort.setText("Add");
        btnAddPort.setName("btnAddPort");
        btnAddPort.setOpaque(false);
        btnAddPort.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnAddPortMouseClicked(evt);
            }
        });

        btnEditPort.setText("Edit");
        btnEditPort.setName("btnSetting");
        btnEditPort.setOpaque(false);
        btnEditPort.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnEditPortMouseClicked(evt);
            }
        });

        btnRemovePort.setText("Remove");
        btnRemovePort.setName("btnSetting");
        btnRemovePort.setOpaque(false);
        btnRemovePort.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnRemovePortMouseClicked(evt);
            }
        });

        lbPort.setText("Port Number:");

        tblPort.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Port", "State"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tblPort.setEditingColumn(0);
        tblPort.setEditingRow(0);
        tblPort.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        tblPort.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblPortMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tblPort);

        btnStart.setBackground(new java.awt.Color(67, 67, 67));
        btnStart.setFont(new java.awt.Font("Tahoma", 1, 20)); // NOI18N
        btnStart.setForeground(new java.awt.Color(153, 191, 255));
        btnStart.setText("START");
        btnStart.setName("btnStart");
        btnStart.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnStartActionPerformed(evt);
            }
        });

        lbTest.setText("jLabel2");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(lbPort)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtPortNumber))
                    .addComponent(btnRemovePort, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnEditPort, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnAddPort, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 67, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(btnStart, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(lbTest)
                        .addGap(90, 90, 90))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(32, 32, 32)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtPortNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lbPort)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addComponent(lbTest)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(27, 27, 27)
                        .addComponent(btnStart, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(btnAddPort, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnEditPort, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnRemovePort, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(23, 23, 23))))
        );

        btnStart.getAccessibleContext().setAccessibleName("");

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Config"));

        btnClearCache.setText("Clear Cache");
        btnClearCache.setName("btnClearCache");
        btnClearCache.setOpaque(false);
        btnClearCache.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnClearCacheActionPerformed(evt);
            }
        });

        lbMb.setText("Mb");

        lbMaxSize.setText("Max Size :");

        cbCache.setText("Cache");
        cbCache.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                cbCacheMouseClicked(evt);
            }
        });
        cbCache.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbCacheItemStateChanged(evt);
            }
        });

        cbChangeProxy.setText("Change Proxy");
        cbChangeProxy.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                cbChangeProxyMouseClicked(evt);
            }
        });
        cbChangeProxy.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbChangeProxyItemStateChanged(evt);
            }
        });

        lbHost.setText("Host:");

        txtHost_ChangProxy.setEnabled(false);
        txtHost_ChangProxy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtHost_ChangProxyActionPerformed(evt);
            }
        });

        lbPort_ChangeProxy.setText("Port:");

        txtPort_ChangeProxy.setEnabled(false);
        txtPort_ChangeProxy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtPort_ChangeProxyActionPerformed(evt);
            }
        });

        txtMaxSize.setEnabled(false);
        txtMaxSize.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtMaxSizeActionPerformed(evt);
            }
        });

        btnAplly_Config.setText("Apply");
        btnAplly_Config.setEnabled(false);
        btnAplly_Config.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAplly_ConfigActionPerformed(evt);
            }
        });

        btnCancel_Config.setText("Cancel");
        btnCancel_Config.setEnabled(false);
        btnCancel_Config.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancel_ConfigActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(cbCache)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(lbMaxSize))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(cbChangeProxy)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(lbHost)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtMaxSize, javax.swing.GroupLayout.DEFAULT_SIZE, 122, Short.MAX_VALUE)
                    .addComponent(txtHost_ChangProxy))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(lbPort_ChangeProxy)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtPort_ChangeProxy))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(lbMb)
                        .addGap(18, 18, 18)
                        .addComponent(btnClearCache, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addGap(36, 36, 36)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnAplly_Config, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnCancel_Config, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(14, 14, 14)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnClearCache)
                    .addComponent(lbMb)
                    .addComponent(lbMaxSize)
                    .addComponent(cbCache)
                    .addComponent(txtMaxSize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnAplly_Config))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbChangeProxy)
                    .addComponent(txtHost_ChangProxy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbHost)
                    .addComponent(lbPort_ChangeProxy)
                    .addComponent(txtPort_ChangeProxy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCancel_Config))
                .addContainerGap(18, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout panelMainLayout = new javax.swing.GroupLayout(panelMain);
        panelMain.setLayout(panelMainLayout);
        panelMainLayout.setHorizontalGroup(
            panelMainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelMainLayout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(panelMainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(46, 46, 46))
        );
        panelMainLayout.setVerticalGroup(
            panelMainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelMainLayout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        tabMain.addTab("  Home  ", panelMain);

        panelALC.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2));
        panelALC.setAutoscrolls(true);
        panelALC.setPreferredSize(new java.awt.Dimension(570, 440));

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Filter"));
        jPanel4.setToolTipText("");

        cbImage.setText("Image");
        cbImage.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbImageActionPerformed(evt);
            }
        });

        cbAudio.setText("Audio");
        cbAudio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbAudioActionPerformed(evt);
            }
        });

        cbVideo.setText("Video");
        cbVideo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbVideoActionPerformed(evt);
            }
        });

        cbFlash.setText("Flash");
        cbFlash.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbFlashActionPerformed(evt);
            }
        });

        cbImage_All.setText("All");
        cbImage_All.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbImage_AllActionPerformed(evt);
            }
        });

        cbAudio_All.setText("All");
        cbAudio_All.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbAudio_AllActionPerformed(evt);
            }
        });

        cbVideo_All.setText("All");
        cbVideo_All.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbVideo_AllActionPerformed(evt);
            }
        });

        cbFlash_All.setText("All");
        cbFlash_All.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbFlash_AllActionPerformed(evt);
            }
        });

        cbLock.setText("Lock");
        cbLock.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbLockActionPerformed(evt);
            }
        });

        cbLock_All.setText("All");
        cbLock_All.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbLock_AllActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cbLock)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cbVideo)
                            .addComponent(cbFlash)
                            .addComponent(cbAudio)
                            .addComponent(cbImage))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                            .addComponent(cbImage_All)
                            .addComponent(cbAudio_All)
                            .addComponent(cbVideo_All)
                            .addComponent(cbFlash_All)
                            .addComponent(cbLock_All))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbImage)
                    .addComponent(cbImage_All))
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbAudio)
                    .addComponent(cbAudio_All))
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbVideo)
                    .addComponent(cbVideo_All))
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbFlash)
                    .addComponent(cbFlash_All))
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbLock)
                    .addComponent(cbLock_All))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder("BlackList"));

        jPanel5.setLayout(new javax.swing.BoxLayout(jPanel5, javax.swing.BoxLayout.LINE_AXIS));

        lstDomain.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        lstDomain.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                lstDomainValueChanged(evt);
            }
        });
        jScrollPane3.setViewportView(lstDomain);

        jPanel5.add(jScrollPane3);

        tabBlackList.addTab("Domain", jPanel5);

        jPanel6.setLayout(new javax.swing.BoxLayout(jPanel6, javax.swing.BoxLayout.LINE_AXIS));

        lstIP.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                lstIPValueChanged(evt);
            }
        });
        jScrollPane4.setViewportView(lstIP);

        jPanel6.add(jScrollPane4);

        tabBlackList.addTab("IP", jPanel6);

        btnBlackList_Add.setText("Add");
        btnBlackList_Add.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBlackList_AddActionPerformed(evt);
            }
        });

        btnBlackList_Update.setText("Update");
        btnBlackList_Update.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBlackList_UpdateActionPerformed(evt);
            }
        });

        jLabel10.setText("Info");

        btnBlackList_Delete.setText("Delete");
        btnBlackList_Delete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBlackList_DeleteActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(btnBlackList_Update, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnBlackList_Add, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel7Layout.createSequentialGroup()
                            .addComponent(jLabel10)
                            .addGap(18, 18, 18)
                            .addComponent(txtBlackList_Info, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(btnBlackList_Delete, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(tabBlackList, javax.swing.GroupLayout.PREFERRED_SIZE, 202, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addGap(31, 31, 31)
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel10)
                            .addComponent(txtBlackList_Info, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(32, 32, 32)
                        .addComponent(btnBlackList_Add, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(26, 26, 26)
                        .addComponent(btnBlackList_Update, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnBlackList_Delete, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(tabBlackList, javax.swing.GroupLayout.PREFERRED_SIZE, 360, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        btnACL_Cancel.setText("Cancel");
        btnACL_Cancel.setName("btnACL_Cancel");
        btnACL_Cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnACL_CancelActionPerformed(evt);
            }
        });

        btnACL_Apply.setText("Apply");
        btnACL_Apply.setName("btnACL_Apply");
        btnACL_Apply.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnACL_ApplyActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelALCLayout = new javax.swing.GroupLayout(panelALC);
        panelALC.setLayout(panelALCLayout);
        panelALCLayout.setHorizontalGroup(
            panelALCLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelALCLayout.createSequentialGroup()
                .addGap(692, 692, 692)
                .addComponent(lblName)
                .addGap(0, 0, Short.MAX_VALUE))
            .addGroup(panelALCLayout.createSequentialGroup()
                .addGap(17, 17, 17)
                .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelALCLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnACL_Cancel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnACL_Apply, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(77, 77, 77))
        );
        panelALCLayout.setVerticalGroup(
            panelALCLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelALCLayout.createSequentialGroup()
                .addComponent(lblName)
                .addGap(29, 29, 29)
                .addGroup(panelALCLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(panelALCLayout.createSequentialGroup()
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(30, 30, 30)
                        .addComponent(btnACL_Apply, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnACL_Cancel, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(36, 36, 36))
        );

        tabMain.addTab("ACL", panelALC);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(palTop, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addComponent(tabMain, javax.swing.GroupLayout.PREFERRED_SIZE, 721, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(palTop, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(tabMain, javax.swing.GroupLayout.PREFERRED_SIZE, 461, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(21, Short.MAX_VALUE))
        );

        tabMain.getAccessibleContext().setAccessibleName("  Home  ");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        //Xy ly Config truoc khi Load
        loadConfig();
        
        //Xy ly thong tin control PortTable
        ListPort = new ArrayList<>();
        InputFile_ListPort("List.port");
        loadTablePort();
        
        //--------------
        LoadListDomain();
        LoadListIP();
        //Xy ly cac Thread port trong danh sach
        Listproxy =new ArrayList<>();
        for(int i = 0; i<iCountPort;i++)
        {
            Port_Thread temp = new Port_Thread(ListPort.get(i).getPortNumber(),config,ListDomain,ListIP);
            Listproxy.add(temp);
            if(ListPort.get(i).getState()==1)
            {
                Listproxy.get(i).setFlag_State(true);
                Listproxy.get(i).start();
            }
        }
    }//GEN-LAST:event_formWindowOpened

    private void tabMainStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_tabMainStateChanged
        // TODO add your handling code here:
        if (tabMain.getSelectedIndex() == 0 && flag == 1)
        {
            //JOptionPane.showMessageDialog(null,"Da chon Home");
        }
        if (tabMain.getSelectedIndex() == 1 && flag == 1) 
        {
            //JOptionPane.showMessageDialog(null,"Da chon ACL");
//                CreateTableDoMain();
//                CreateTableIP();
        }
        flag = 1;
    }//GEN-LAST:event_tabMainStateChanged
    //<editor-fold defaultstate="collapsed" desc="cac Su kien control tab Home">
    private void btnStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStartActionPerformed
        if(indexListRow_Port !=-1)
        {
            lbTest.setText(String.valueOf(indexListRow_Port));
            if (!Listproxy.get(indexListRow_Port).getFlag_State()) //Kiem tra xem port dang chon stop hay run
            {
                //Port dang Stop
                //Cap nhat lai trang thai trong table va trong arraylist port
                tblmodel.setValueAt("Run",indexListRow_Port, 1);
                MyPort temp = ListPort.get(indexListRow_Port);
                temp.setState(1);
                ListPort.set(indexListRow_Port,temp);
                
                Listproxy.get(indexListRow_Port).setFlag_State(true); //gan lai bien flag(dang run) = true
                btnStart.setText("STOP");               //thay doi text cua button 
                //Lay trang thai cua thread dang xu ly port nay
                Thread.State stateThread = Listproxy.get(indexListRow_Port).getState();
                
               
                if (stateThread == Thread.State.TERMINATED) 
                {
                    //Port nay da ket thuc , can duoc khoi tao lai 
                    Port_Thread proxy = new Port_Thread(Listproxy.get(indexListRow_Port).getPort(),config,ListDomain,ListIP);
                    Listproxy.set(indexListRow_Port, proxy);
                }
                if (stateThread == Thread.State.NEW || stateThread == Thread.State.TERMINATED)
                    Listproxy.get(indexListRow_Port).start();    //bat dau khoi dong 1 thread 
                OutputFile_ListPort("List.port");
            } else //Port dang run
            {
                tblmodel.setValueAt("Stop",indexListRow_Port, 1);
                MyPort temp = ListPort.get(indexListRow_Port);
                temp.setState(0);
                ListPort.set(indexListRow_Port,temp);
                Listproxy.get(indexListRow_Port).setFlag_State(false); //Gan lai bien flag = false 
                btnStart.setText("START"); //thay doi text cua button
                OutputFile_ListPort("List.port");
            }
        }
    }//GEN-LAST:event_btnStartActionPerformed

    private void btnAddPortMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnAddPortMouseClicked
        Object newRow[] = new Object[2];
        int iPortNumber ;
        try {
            iPortNumber = Integer.parseInt(txtPortNumber.getText());
            if(!(iPortNumber>1000 && iPortNumber < 10000))
                JOptionPane.showMessageDialog(this,"PortNumber không hợp lệ");
            else
            {
                for(int i = 0 ;i<iCountPort;i++)
                    if(ListPort.get(i).getPortNumber() == iPortNumber)
                    {
                        JOptionPane.showMessageDialog(this,"PortNumber is exist");
                        return;
                    }
                newRow[0] = iPortNumber;
                newRow[1] = "Stop";
                MyPort temp = new MyPort(iPortNumber,0);
                ListPort.add(temp);
                tblmodel.addRow(newRow);
                iCountPort++;
                OutputFile_ListPort("List.port");
            }
        } catch (NumberFormatException | HeadlessException e) {
            JOptionPane.showMessageDialog(this,"Dử liệu nhập không hợp lệ");
        }
    }//GEN-LAST:event_btnAddPortMouseClicked

    private void btnRemovePortMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnRemovePortMouseClicked
        if(indexListRow_Port != -1)
        {
            if(ListPort.get(indexListRow_Port).getState() ==1)
                JOptionPane.showMessageDialog(this,"Port is running");
            else
            {
                tblmodel.removeRow(indexListRow_Port);
                ListPort.remove(indexListRow_Port);
                txtPortNumber.setText(null);
                indexListRow_Port =-1;
                iCountPort--;
                OutputFile_ListPort("List.port");
            }
        }
    }//GEN-LAST:event_btnRemovePortMouseClicked

    private void btnEditPortMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnEditPortMouseClicked
        if(indexListRow_Port != -1)
        {
            if(ListPort.get(indexListRow_Port).getState() ==1)
                JOptionPane.showMessageDialog(this,"Port is running");
            else
            {
                try {
                    int NewPort = Integer.parseInt(txtPortNumber.getText());
                     if(!(NewPort>1023 && NewPort < 10000))
                        JOptionPane.showMessageDialog(this,"PortNumber không hợp lệ");
                     else
                     {
                        MyPort temp = ListPort.get(indexListRow_Port);
                        temp.setPortNumber(NewPort);
                        ListPort.set(indexListRow_Port, temp);
                        tblmodel.setValueAt(NewPort, indexListRow_Port,0);
                        OutputFile_ListPort("List.port");
                     }
                    
                } catch (NumberFormatException | HeadlessException e) {
                    JOptionPane.showMessageDialog(this,"Dử liệu nhập không hợp lệ");
                }
                
            }
        }
    }//GEN-LAST:event_btnEditPortMouseClicked

    private void tblPortMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblPortMouseClicked
        int index = tblPort.getSelectedRow();

        indexListRow_Port = index;
        lbTest.setText(String.valueOf(indexListRow_Port));
        txtPortNumber.setText(String.valueOf(ListPort.get(index).getPortNumber()));
        int state = ListPort.get(index).getState();
        if(state ==0)
            btnStart.setText("START");
        else
            btnStart.setText("STOP");

    }//GEN-LAST:event_tblPortMouseClicked

    private void cbChangeProxyItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbChangeProxyItemStateChanged
        if(evt.getStateChange() == ItemEvent.SELECTED)
        {
           config.setChangeProxy(true);
           txtHost_ChangProxy.setEnabled(true);
           txtPort_ChangeProxy.setEnabled(true);
        }
        else
        {
            config.setChangeProxy(false);
            txtHost_ChangProxy.setEnabled(false);
            txtPort_ChangeProxy.setEnabled(false);
        }
    }//GEN-LAST:event_cbChangeProxyItemStateChanged

    private void cbCacheItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbCacheItemStateChanged
       if(evt.getStateChange() == ItemEvent.SELECTED)
        {
           txtMaxSize.setEnabled(true);
        }
        else
        {
            txtMaxSize.setEnabled(false);
        }
    }//GEN-LAST:event_cbCacheItemStateChanged

    private void txtHost_ChangProxyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtHost_ChangProxyActionPerformed
        try {
            String strChangeProxy_Host = txtHost_ChangProxy.getText();
            config.setChangeProxy_Host(strChangeProxy_Host);
            btnAplly_Config.setEnabled(true);
            btnCancel_Config.setEnabled(true);
            
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this,"PortNumber Không hợp lệ");
        }
    }//GEN-LAST:event_txtHost_ChangProxyActionPerformed

    private void btnAplly_ConfigActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAplly_ConfigActionPerformed
       btnCancel_Config.setEnabled(false);
       btnAplly_Config.setEnabled(false);
       config.setChangeProxy_Host(txtHost_ChangProxy.getText());
       config.setChangeProxy_Port(Integer.parseInt(txtPort_ChangeProxy.getText()));
       config_history = new Config(config);
       for(int i = 0 ;i<Listproxy.size();i++)
       {
           Listproxy.get(i).setConfig(config);
       }
       config.OutPutFile("Default.config");
    }//GEN-LAST:event_btnAplly_ConfigActionPerformed

    private void btnCancel_ConfigActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancel_ConfigActionPerformed
        btnAplly_Config.setEnabled(false);
        btnCancel_Config.setEnabled(false);
        config = new Config(config_history);
        loadConfig();
    }//GEN-LAST:event_btnCancel_ConfigActionPerformed

    private void txtMaxSizeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtMaxSizeActionPerformed
        btnAplly_Config.setEnabled(true);
        btnCancel_Config.setEnabled(true);
    }//GEN-LAST:event_txtMaxSizeActionPerformed

    private void btnClearCacheActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnClearCacheActionPerformed
       JOptionPane.showMessageDialog(this,"Chức năng đang trong quá trình xử lý");
    }//GEN-LAST:event_btnClearCacheActionPerformed

    private void txtPort_ChangeProxyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtPort_ChangeProxyActionPerformed
        String strChangeProxy_Port = txtPort_ChangeProxy.getText();
        try {
            int ChangeProxy_Port = Integer.parseInt(strChangeProxy_Port);
            config.setChangeProxy_Port(ChangeProxy_Port);
            btnAplly_Config.setEnabled(true);
            btnCancel_Config.setEnabled(true);
            
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this,"PortNumber Không hợp lệ");
        }
    }//GEN-LAST:event_txtPort_ChangeProxyActionPerformed

    private void cbChangeProxyMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cbChangeProxyMouseClicked
        btnAplly_Config.setEnabled(true);
        btnCancel_Config.setEnabled(true);
    }//GEN-LAST:event_cbChangeProxyMouseClicked

    private void cbCacheMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cbCacheMouseClicked
        btnAplly_Config.setEnabled(true);
        btnCancel_Config.setEnabled(true);
    }//GEN-LAST:event_cbCacheMouseClicked
//</editor-fold>
    private void btnBlackList_AddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBlackList_AddActionPerformed
        if(txtBlackList_Info.getText().length()==0)
            JOptionPane.showMessageDialog(this,"Bạn vui lòng nhập thông tin mới");
        else
        {
            String strInfo = txtBlackList_Info.getText();
            ACL_BlackList bl = new ACL_BlackList();
            bl.setName(strInfo);
            if(tabBlackList.getSelectedIndex()==0)
            {   
                for(int i =0;i<iCountDomain;i++)
                    if(strInfo.equals(ListDomain.get(i).getName()))
                    {
                        JOptionPane.showMessageDialog(this,"Domain Name is exist");
                        return ;
                    }
                lsDomainmodel.addElement(strInfo);
                ListDomain.add(bl);
            }
            else
            {
                for(int i =0;i<iCountIP;i++)
                    if(strInfo.equals(ListIP.get(i).getName()))
                    {
                        JOptionPane.showMessageDialog(this,"IP Name is exist");
                        return ;
                    }
                lsIPmodel.addElement(strInfo);
                ListIP.add(bl);
            }
        }
    }//GEN-LAST:event_btnBlackList_AddActionPerformed

    private void btnBlackList_DeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBlackList_DeleteActionPerformed
        if(tabBlackList.getSelectedIndex()==0)
        {
            if(indexListRow_Domain != -1)
            {
                lsDomainmodel.remove(indexListRow_Domain);
                ListDomain.remove(indexListRow_Domain);
                txtBlackList_Info.setText(null);
                indexListRow_Domain=-1;
                iCountDomain--;
            }
        }
        else
        {
            if(indexListRow_IP !=-1)
            {
                lsIPmodel.remove(indexListRow_IP);
                ListIP.remove(indexListRow_IP);
                txtBlackList_Info.setText(null);
                indexListRow_IP =-1;
                iCountIP--;
            }
        }
    }//GEN-LAST:event_btnBlackList_DeleteActionPerformed

    private void btnBlackList_UpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBlackList_UpdateActionPerformed
        if(txtBlackList_Info.getText().length()==0)
            JOptionPane.showMessageDialog(this,"Chưa nhập dử liệu");
        else
        {
            String strInfo = txtBlackList_Info.getText();
            ACL_BlackList bl = new ACL_BlackList();
            bl.setName(strInfo);
            if(tabBlackList.getSelectedIndex()==0)
            {   
                for(int i =0;i<iCountDomain;i++)
                    if(strInfo.equals(ListDomain.get(i).getName()))
                    {
                        JOptionPane.showMessageDialog(this,"Domain Name is exist");
                        return ;
                    }
                lsDomainmodel.setElementAt(strInfo, indexListRow_Domain);
                ListDomain.set(indexListRow_Domain, bl);
            }
            else
            {
                for(int i =0;i<iCountIP;i++)
                    if(strInfo.equals(ListIP.get(i).getName()))
                    {
                        JOptionPane.showMessageDialog(this,"IP Name is exist");
                        return ;
                    }
                lsIPmodel.setElementAt(strInfo, indexListRow_IP);
                ListIP.set(indexListRow_IP, bl);
            }
        }
    }//GEN-LAST:event_btnBlackList_UpdateActionPerformed

    private void btnACL_ApplyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnACL_ApplyActionPerformed
        OutputFile_BlackList("Ip.blacklist", ListIP);
        OutputFile_BlackList("Domain.blacklist", ListDomain);
        config.OutPutFile("Default.config");
        
    }//GEN-LAST:event_btnACL_ApplyActionPerformed

    private void btnACL_CancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnACL_CancelActionPerformed
        LoadListDomain();
        LoadListIP();
        loadConfig();
    }//GEN-LAST:event_btnACL_CancelActionPerformed

    private void lstDomainValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_lstDomainValueChanged
        if(lstDomain.getSelectedIndex()!=-1)
        {
            indexListRow_Domain =lstDomain.getSelectedIndex();
            txtBlackList_Info.setText(lstDomain.getSelectedValue().toString());
            cbLock.setSelected(true);
            cbAudio.setSelected(true);
            cbFlash.setSelected(true);
            cbImage.setSelected(true);
            cbVideo.setSelected(true);
            if(!ListDomain.get(indexListRow_Domain).getFilter().getLock())
                cbLock.setSelected(false);
            if(!ListDomain.get(indexListRow_Domain).getFilter().getAudio())
                cbAudio.setSelected(false);
            if(!ListDomain.get(indexListRow_Domain).getFilter().getFlash())
                cbFlash.setSelected(false);
            if(!ListDomain.get(indexListRow_Domain).getFilter().getImage())
                cbImage.setSelected(false);
            if(!ListDomain.get(indexListRow_Domain).getFilter().getVideo())
                cbVideo.setSelected(false);
        }
    }//GEN-LAST:event_lstDomainValueChanged

    private void lstIPValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_lstIPValueChanged
        if(lstIP.getSelectedIndex()!=-1)
        {
            indexListRow_IP =lstIP.getSelectedIndex();
            txtBlackList_Info.setText(lstIP.getSelectedValue().toString());  
            cbLock.setSelected(true);
            cbAudio.setSelected(true);
            cbFlash.setSelected(true);
            cbImage.setSelected(true);
            cbVideo.setSelected(true);
            if(!ListIP.get(indexListRow_IP).getFilter().getLock())
                cbLock.setSelected(false);
            if(!ListIP.get(indexListRow_IP).getFilter().getAudio())
                cbAudio.setSelected(false);
            if(!ListIP.get(indexListRow_IP).getFilter().getFlash())
                cbFlash.setSelected(false);
            if(!ListIP.get(indexListRow_IP).getFilter().getImage())
                cbImage.setSelected(false);
            if(!ListIP.get(indexListRow_IP).getFilter().getVideo())
                cbVideo.setSelected(false);

        }
    }//GEN-LAST:event_lstIPValueChanged

    private void cbImageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbImageActionPerformed
        if(tabBlackList.getSelectedIndex()==0)
        {
            if(cbImage.isSelected())
                ListDomain.get(indexListRow_Domain).getFilter().setImage(true);
            else
                ListDomain.get(indexListRow_Domain).getFilter().setImage(false);  
        }
        else
        {
            if(cbImage.isSelected())
                ListIP.get(indexListRow_IP).getFilter().setImage(true);
            else
                ListIP.get(indexListRow_IP).getFilter().setImage(false);  
        }
             
    }//GEN-LAST:event_cbImageActionPerformed

    private void cbAudioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbAudioActionPerformed
        if(tabBlackList.getSelectedIndex()==0)
        {
            if(cbAudio.isSelected())
                ListDomain.get(indexListRow_Domain).getFilter().setAudio(true);
            else
                ListDomain.get(indexListRow_Domain).getFilter().setAudio(false);  
        }
        else
        {
            if(cbAudio.isSelected())
                ListIP.get(indexListRow_IP).getFilter().setAudio(true);
            else
                ListIP.get(indexListRow_IP).getFilter().setAudio(false);  
        }
    }//GEN-LAST:event_cbAudioActionPerformed

    private void cbVideoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbVideoActionPerformed
        if(tabBlackList.getSelectedIndex()==0)
        {
            if(cbVideo.isSelected())
                ListDomain.get(indexListRow_Domain).getFilter().setVideo(true);
            else
                ListDomain.get(indexListRow_Domain).getFilter().setVideo(false);  
        }
        else
        {
            if(cbVideo.isSelected())
                ListIP.get(indexListRow_IP).getFilter().setVideo(true);
            else
                ListIP.get(indexListRow_IP).getFilter().setVideo(false);  
        }
    }//GEN-LAST:event_cbVideoActionPerformed

    private void cbFlashActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbFlashActionPerformed
        if(tabBlackList.getSelectedIndex()==0)
        {
            if(cbFlash.isSelected())
                ListDomain.get(indexListRow_Domain).getFilter().setFlash(true);
            else
                ListDomain.get(indexListRow_Domain).getFilter().setFlash(false);  
        }
        else
        {
            if(cbFlash.isSelected())
                ListIP.get(indexListRow_IP).getFilter().setFlash(true);
            else
                ListIP.get(indexListRow_IP).getFilter().setFlash(false);  
        }
    }//GEN-LAST:event_cbFlashActionPerformed

    private void cbLockActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbLockActionPerformed
        if(tabBlackList.getSelectedIndex()==0)
        {
            if(cbLock.isSelected())
            {
                ListDomain.get(indexListRow_Domain).getFilter().setLock(true);
                //Khi set lock = true thi tat cac cac thuoc tinh filter duoc set true
                ListDomain.get(indexListRow_Domain).getFilter().setAudio(true);
                ListDomain.get(indexListRow_Domain).getFilter().setImage(true);
                ListDomain.get(indexListRow_Domain).getFilter().setVideo(true);
                ListDomain.get(indexListRow_Domain).getFilter().setFlash(true);
            }
            else
                ListDomain.get(indexListRow_Domain).getFilter().setLock(false);  
        }
        else
        {
            if(cbLock.isSelected())
            {
                ListIP.get(indexListRow_IP).getFilter().setLock(true);
                ListIP.get(indexListRow_IP).getFilter().setAudio(true);
                ListIP.get(indexListRow_IP).getFilter().setImage(true);
                ListIP.get(indexListRow_IP).getFilter().setVideo(true);
                ListIP.get(indexListRow_IP).getFilter().setFlash(true);
            }
            else
                ListIP.get(indexListRow_IP).getFilter().setLock(false);  
        }
        cbAudio.setSelected(true);
        cbFlash.setSelected(true);
        cbImage.setSelected(true);
        cbVideo.setSelected(true);
    }//GEN-LAST:event_cbLockActionPerformed

    private void cbImage_AllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbImage_AllActionPerformed
        if(cbImage_All.isSelected())
            config.getFilter().setImage(true);
        else
            config.getFilter().setImage(false);
    }//GEN-LAST:event_cbImage_AllActionPerformed

    private void cbAudio_AllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbAudio_AllActionPerformed
        if(cbAudio_All.isSelected())
            config.getFilter().setAudio(true);
        else
            config.getFilter().setAudio(false);
    }//GEN-LAST:event_cbAudio_AllActionPerformed

    private void cbVideo_AllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbVideo_AllActionPerformed
        if(cbVideo_All.isSelected())
            config.getFilter().setVideo(true);
        else
            config.getFilter().setVideo(false);
    }//GEN-LAST:event_cbVideo_AllActionPerformed

    private void cbFlash_AllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbFlash_AllActionPerformed
        if(cbFlash_All.isSelected())
            config.getFilter().setFlash(true);
        else
            config.getFilter().setFlash(false);
    }//GEN-LAST:event_cbFlash_AllActionPerformed

    private void cbLock_AllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbLock_AllActionPerformed
       if(cbLock_All.isSelected())
       {
           //khi check clock thi tat cac cac checkbox con lai deu duoc check
           config.getFilter().setAudio(true);
           config.getFilter().setFlash(true);
           config.getFilter().setImage(true);
           config.getFilter().setLock(true);
           config.getFilter().setVideo(true);
           
           cbAudio_All.setSelected(true);
           cbFlash_All.setSelected(true);
           cbImage_All.setSelected(true);
           cbVideo_All.setSelected(true);
       }
       else
           config.getFilter().setLock(false);
    }//GEN-LAST:event_cbLock_AllActionPerformed

    private void btnAboutMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnAboutMouseClicked
        // TODO add your handling code here:
        frmAbout ab = new frmAbout(this,true);
        ab.show();
    }//GEN-LAST:event_btnAboutMouseClicked

    private void btnHelpMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnHelpMouseClicked
        // TODO add your handling code here:
        File file = new File("Help/Help.CHM");
        try
        {
            Desktop.getDesktop().open(file);
        }catch(Exception ex)
        {
            ex.printStackTrace();
        }
    }//GEN-LAST:event_btnHelpMouseClicked
    
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]){
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new MainFrame().setVisible(true);
            }

        });    
    }
    //<editor-fold defaultstate="collapsed" desc="Xu ly tab ACL ">
    private void RefreshFilter()
    {
        cbAudio.setSelected(false);
          cbVideo.setSelected(false);
           cbImage.setSelected(false);
            cbLock.setSelected(false);
             cbFlash.setSelected(false);
           
    }
    private void LoadListDomain()
    {
        ListDomain = new ArrayList<>();
        lsDomainmodel = new DefaultListModel();
        iCountDomain =InputFile_BlackList("Domain.blacklist",ListDomain);
        lsDomainmodel =LoadBlackList(lstDomain, ListDomain);
        lstDomain.setModel(lsDomainmodel);
    }
    private void LoadListIP()
    {
        ListIP = new ArrayList<>();
        lsIPmodel = new DefaultListModel();
        iCountIP = InputFile_BlackList("IP.blacklist",ListIP);
        lsIPmodel=LoadBlackList(lstIP, ListIP);
        lstIP.setModel(lsIPmodel);
    }
    private DefaultListModel LoadBlackList(JList jls,ArrayList<ACL_BlackList> arr)
    {
        DefaultListModel model = new DefaultListModel();
        for(int i =0 ;i<arr.size();i++)
        {
            model.addElement(arr.get(i).getName());
        }
        return model;
    }
    private int InputFile_BlackList(String fileName,ArrayList<ACL_BlackList> arr)
    {
        //Cau truc file
        //Dong 1: n: so luong domain
        //n dong tiep theo : Name Lock  Audio Image Video Flash
        //
        try {
            fis = new FileInputStream(fileName);
            bffR = new BufferedReader(new InputStreamReader(fis));
            String strNumber = bffR.readLine();
            int count = Integer.parseInt(strNumber);
            for(int i = 0;i<count;i++)
            {
                String str[] = bffR.readLine().split(" ");
                ACL_BlackList bl = new ACL_BlackList();
                bl.setName(str[0]);
                ACL_Filter ft = new ACL_Filter();
                ft.setLock(Boolean.valueOf(str[1]));
                ft.setAudio(Boolean.valueOf(str[2]));
                ft.setImage(Boolean.valueOf(str[3]));
                ft.setVideo(Boolean.valueOf(str[4]));
                ft.setFlash(Boolean.valueOf(str[5]));
                
                bl.setFilter(ft);
                arr.add(bl);
            }
            fis.close();
            bffR.close();
            return count;
        }
        catch (IOException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
        return 0;
    }
    private void OutputFile_BlackList(String fileName,ArrayList<ACL_BlackList> arr)
    {
        //Cau truc file
        //Dong 1: n: so luong domain
        //n dong tiep theo : Name Lock  Audio Image Video Flash
        //
        try {
            fos = new FileOutputStream(fileName);
            ps = new PrintStream(fos);
            ps.println(String.valueOf(arr.size()));
            for(int i = 0;i<arr.size();i++)
            {
                ps.print(arr.get(i).getName());
                ps.print(" ");
                ps.print(arr.get(i).getFilter().getLock());
                ps.print(" ");
                ps.print(arr.get(i).getFilter().getAudio());
                ps.print(" ");
                ps.print(arr.get(i).getFilter().getImage());
                ps.print(" ");
                ps.print(arr.get(i).getFilter().getVideo());
                ps.print(" ");
                ps.println(arr.get(i).getFilter().getFlash());
            }
            fis.close();
            bffR.close();
        }
        catch (IOException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    //</editor-fold>
    
    //<editor-fold defaultstate="collapsed" desc="Xu ly config">
    private void loadConfig()
    {
        config = new Config();  
        config.InputFile("Default.config");
        config_history = new Config(config);
        //Change proxy
        if(config.IsChangeProxy())
        {
            txtHost_ChangProxy.setText(config.getChangeProxy_Host());
            txtPort_ChangeProxy.setText(String.valueOf(config.getChangeProxy_Port()));
            txtHost_ChangProxy.setEnabled(true);
            txtPort_ChangeProxy.setEnabled(true);
            cbChangeProxy.setSelected(true);
        }
        else
        {
            txtHost_ChangProxy.setEnabled(false);
            txtPort_ChangeProxy.setEnabled(false);
            txtHost_ChangProxy.setText(config.getChangeProxy_Host());
            txtPort_ChangeProxy.setText(String.valueOf(config.getChangeProxy_Port()));
            cbChangeProxy.setSelected(false);
        }
        //ACL - Filter
        cbImage_All.setSelected(true);
        cbAudio_All.setSelected(true);
        cbFlash_All.setSelected(true);
        cbVideo_All.setSelected(true);
        cbLock_All.setSelected(true);
        if(!config.getFilter().getLock())
        {
            cbLock_All.setSelected(false);
            if(!config.getFilter().getImage())
                cbImage_All.setSelected(false);
            if(!config.getFilter().getAudio())
                cbAudio_All.setSelected(false);
            if(!config.getFilter().getVideo())
                cbFlash_All.setSelected(false);
            if(!config.getFilter().getVideo())
                cbVideo_All.setSelected(false);
        }
        
    }
    //</editor-fold>
    
    //<editor-fold defaultstate="collapsed" desc="Xu ly  List Port">
    private void loadTablePort()
    {
        Object rowData[][] = new Object[iCountPort][2];
        for(int i = 0; i< iCountPort; i++)
        {
            rowData[i][0] = ListPort.get(i).getPortNumber();
            if(ListPort.get(i).getState() ==0)
                rowData[i][1] = "Stop";
            else
                rowData[i][1] = "Run";
        }
        String column[] = {"Port","State"};
        tblmodel = new DefaultTableModel(rowData,column);
        tblPort.setModel(tblmodel);
    }
    private void InputFile_ListPort(String fileName)
    {
        try {
            fis = new FileInputStream(fileName);
            //iNumberPort = Character.digit(((char)fis.read()),10);
            bffR = new BufferedReader(new InputStreamReader(fis));
            String strNumber = bffR.readLine();
            iCountPort = Integer.parseInt(strNumber);
            
            for(int i = 0;i<iCountPort;i++)
            {
                String str[] = bffR.readLine().split(" ");
                MyPort temp = new MyPort();
                temp.setPortNumber(Integer.parseInt(str[0]));
                temp.setState(Integer.parseInt(str[1]));
                ListPort.add(temp);
            }
            fis.close();
            bffR.close();
        }
        catch (IOException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    private void OutputFile_ListPort(String fileName)
    {
        try {
            fos = new FileOutputStream(fileName);
            ps = new PrintStream(fos);
            ps.println(String.valueOf(iCountPort));
            for(int i = 0 ; i<iCountPort;i++)
            {
                ps.println(String.valueOf(ListPort.get(i).getPortNumber())+" " +String.valueOf(ListPort.get(i).getState()));
            }
        } catch (FileNotFoundException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    //</editor-fold>
    
    // <editor-fold defaultstate="collapsed" desc=" CODE THANH TAM - XU LY XML" >
//    public void CreateTableDoMain()
//    {
//        String[] title = new String[7];
//     DefaultTableModel tblmodel = new DefaultTableModel();
//     tblmodel = DocFileXML("Domain", tblmodel,title);
//     //tblDoMain.setModel(tblmodel);
//    }
//    
//    public void CreateTableIP()
//    {
//     String[] title = new String[7];
//     DefaultTableModel tblmodel = new DefaultTableModel();
//     tblmodel = DocFileXML("IP", tblmodel,title);
//     //tblIP.setModel(tblmodel);
//    }
//    
//    public void CreateTablePort(DefaultTableModel tblmodel)
//    {
//        String[] title = new String[2];
//        tblmodel = DocFileXML("Port", tblmodel,title);
//        for(int i = 0; i< tblmodel.getRowCount(); i++)
//            for(int j = 0; j< tblmodel.getColumnCount(); j++)
//            {
//                if(tblmodel.getValueAt(i,j).equals("0"))
//                    tblmodel.setValueAt("Stop", i, j);
//                if(tblmodel.getValueAt(i,j).equals("1"))
//                    tblmodel.setValueAt("Start", i, j);
//            }
//        tblPort.setModel(tblmodel);
//    }
//    
//    public DefaultTableModel DocFileXML(String fName, DefaultTableModel md,String[] title)
//    {
//        
//        title[0] = "Name";
//        int flag1 = 0;
//        try {
//		File fXmlFile = new File(fName+".xml");
//		DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
//		DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
//		Document doc = dBuilder.parse(fXmlFile);
//		doc.getDocumentElement().normalize();
// 
//		//System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
//                NodeList nList = doc.getElementsByTagName("Link");
//		//System.out.println("-----------------------"+nList.getLength());
//                String data[][] = new String[nList.getLength()][7];
//		for (int temp = 0; temp < nList.getLength(); temp++) {
// 
//		   Node nNode = nList.item(temp);
//                   NamedNodeMap attrs = nNode.getAttributes();
//                    for (int i = 0; i < attrs.getLength(); i++) 
//                    {
//                        Node attr = (Node) attrs.item(i);
//                        if(flag1 == 0)
//                            title[i+1]=attr.getNodeName().trim().toString();
//                        data[temp][i+1]=attr.getNodeValue().trim().toString();
//                        //System.out.print(" " + attr.getNodeName().trim() + "=\"" + attr.getNodeValue().trim() + "\"");
//                    }
//                    flag1 = 1;
//                    if (nNode.getNodeType() == Node.ELEMENT_NODE) 
//                    {
//                        Element eElement = (Element) nNode;
//                        //System.out.println("Link : " + getTagValue("Name", eElement));
//                        data[temp][0] = getTagValue("Name", eElement).trim();
//                    } 
//		}
//                md = new DefaultTableModel(data, title);
//	  } catch (Exception e) {
//		e.printStackTrace();
//	  }
//        return md;
//    }
//    
//    private static String getTagValue(String sTag, Element eElement) {
//	NodeList nlList = eElement.getElementsByTagName(sTag).item(0).getChildNodes();
// 
//        Node nValue = (Node) nlList.item(0);
// 
//	return nValue.getNodeValue();
//  }
//    
//    public void GhiFile(String fName,TableModel md)
//    {
//        try {
// 
//		DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
//		DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
// 
//		// root elements
//		Document doc = docBuilder.newDocument();
//		Element rootElement = doc.createElement(fName);
//		doc.appendChild(rootElement);
// 
//                for(int i = 0; i < md.getRowCount(); i++)
//                {
//                    // link elements
//                    Element link = doc.createElement("Link");
//                    rootElement.appendChild(link);
//                    for(int j = 0; j< md.getColumnCount(); j++)
//                    {
//                        if(md.getColumnName(j).equals("Name"))
//                        {
//                            // name elements
//                            Element name = doc.createElement(md.getColumnName(j));
//                            name.appendChild(doc.createTextNode(md.getValueAt(i,j).toString()));
//                            link.appendChild(name);
//                        }
//                        else
//                        {
//                        // set attribute to link element
//                        Attr attrID = doc.createAttribute(md.getColumnName(j));
//                        attrID.setValue(md.getValueAt(i,j).toString());
//                        link.setAttributeNode(attrID);
//                        }
//                    }
//                    
//                }
//                
//                
//		// write the content into xml file
//		TransformerFactory transformerFactory = TransformerFactory.newInstance();
//		Transformer transformer = transformerFactory.newTransformer();
//		DOMSource source = new DOMSource(doc);
//		StreamResult result = new StreamResult(new File(fName+".xml"));
// 
//		// Output to console for testing
//		// StreamResult result = new StreamResult(System.out);
// 
//		transformer.transform(source, result);
// 
//		System.out.println("File saved!");
// 
//	  } catch (ParserConfigurationException pce) {
//		pce.printStackTrace();
//	  } catch (TransformerException tfe) {
//		tfe.printStackTrace();
//	  }       
//    }
//    private void RefeshTable()
//    {
////        for(int i = 0; i < tblDoMain.getColumnCount(); i++)
////                for(int j = 0; j < tblDoMain.getRowCount(); j++)
////                {
////                    tblDoMain.setValueAt("", j, i);
////                }
//    }
    //</editor-fold>
    
    //<editor-fold  defaultstate="collapsed" desc=" Khai bao cac bien control ">
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnACL_Apply;
    private javax.swing.JButton btnACL_Cancel;
    private javax.swing.JButton btnAbout;
    private javax.swing.JButton btnAddPort;
    private javax.swing.JButton btnAplly_Config;
    private javax.swing.JButton btnBlackList_Add;
    private javax.swing.JButton btnBlackList_Delete;
    private javax.swing.JButton btnBlackList_Update;
    private javax.swing.JButton btnCancel_Config;
    private javax.swing.JButton btnClearCache;
    private javax.swing.JButton btnEditPort;
    private javax.swing.JButton btnHelp;
    private javax.swing.JButton btnRemovePort;
    private javax.swing.JButton btnStart;
    private javax.swing.JCheckBox cbAudio;
    private javax.swing.JCheckBox cbAudio_All;
    private javax.swing.JCheckBox cbCache;
    private javax.swing.JCheckBox cbChangeProxy;
    private javax.swing.JCheckBox cbFlash;
    private javax.swing.JCheckBox cbFlash_All;
    private javax.swing.JCheckBox cbImage;
    private javax.swing.JCheckBox cbImage_All;
    private javax.swing.JCheckBox cbLock;
    private javax.swing.JCheckBox cbLock_All;
    private javax.swing.JCheckBox cbVideo;
    private javax.swing.JCheckBox cbVideo_All;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JLabel lbHost;
    private javax.swing.JLabel lbMaxSize;
    private javax.swing.JLabel lbMb;
    private javax.swing.JLabel lbPort;
    private javax.swing.JLabel lbPort_ChangeProxy;
    private javax.swing.JLabel lbTest;
    private javax.swing.JLabel lblName;
    private javax.swing.JList lstDomain;
    private javax.swing.JList lstIP;
    private javax.swing.JPanel palTop;
    private javax.swing.JPanel panelALC;
    private javax.swing.JPanel panelMain;
    private javax.swing.JTabbedPane tabBlackList;
    private javax.swing.JTabbedPane tabMain;
    private javax.swing.JTable tblPort;
    private javax.swing.JTextField txtBlackList_Info;
    private javax.swing.JTextField txtHost_ChangProxy;
    private javax.swing.JTextField txtMaxSize;
    private javax.swing.JTextField txtPortNumber;
    private javax.swing.JTextField txtPort_ChangeProxy;
    // End of variables declaration//GEN-END:variables
    //</editor-fold>
    
}
